<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/css/base.css" />
<link rel="stylesheet" type="text/css" href="/static/css/changelists.css" />
<link rel="stylesheet" type="text/css" href="/static/css/dashboard.css" />
<link rel="stylesheet" type="text/css" href="/static/css/forms.css" />
<meta name="robots" content="NONE,NOARCHIVE" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>아이템 지급</title>
<style>
td,th {
	text-align: center;
	width: 100px;
}

.results1 {
	float: left;
	width: 100%;
	margin-left: 30px;
	margin-right: 30px;
	margin-top: 5px;
}
</style>
<script>
            var submit;
            function Clicked(button){
                submit = button;
            }
            
            function validate(value){
                if (isNaN(value) || value < 1) {
                    return false;
                }
                return true;
            }
            
            function edit(){
                if (document.getElementById("memo").value == "") {
                    alert("memo를 입력하세요");
                    return false;
                }
                
                var flag = 0;
                var index = -1;
                if (submit.name.indexOf("add", 0) == 0 || submit.name.indexOf("remove", 0) == 0) {
                    if (submit.name.indexOf("add") == 0) {
                        flag = 1
                        index = parseInt(submit.name.substring(3))
                    }
                    else {
                        flag = 2
                        index = parseInt(submit.name.substring(6))
                    }
                }
                if (flag==0 || index==-1) {
                	alert("뭔일???");
                    return false;
                }
               
                var reward_ids=["id_cash","id_coin","id_bout"];
                var reward_names=["복숭아","코인","당근",];
                
                var id_reward = parseInt(document.getElementById(reward_ids[index]).value, 10);
                if (validate(id_reward) == false) {
                    alert("입력된 수치를 확인해주십시오");
                    return false;
                }
                
                if (flag == 1) {	// 지급
                	if (confirm(document.getElementById("memo").value + "\n" + reward_names[index] + document.getElementById(reward_ids[index]).value + " "+ reward_names[index] +"을(를) 지급 합니다. \n지급하시겠습니까?")) {
                        document.forms["edit-form"].submit();
                    }
                    else {
                        return false;
                    }
                }
                else { // 회수
                	if (confirm(document.getElementById("memo").value + "\n" + reward_names[index] + document.getElementById(reward_ids[index]).value + " "+ reward_names[index] +"을(를) 회수 합니다. \n회수하시겠습니까?")) {
                        document.forms["edit-form"].submit();
                    }
                    else {
                        return false;
                    }
                }
            }
        </script>
</head>
<body>
  <div style="margin-left: 30px;">
    <label style="width: 300px;"> <br />
      <h1>앱 ID : {{userId}}</h1>
    </label>
  </div>
  <br />
  <br /> {{result}}
  <form id="edit-form" onsubmit="return(edit());" action="" method="post">
    <div class="results1">
      <table class="result_list">
        <thead>
          <tr>
            <th class="sortable" scope="col" style="text-align: center;">종류</th>
            <th class="sortable" scope="col" style="text-align: center;">수량</th>
            <th class="sortable" scope="col" style="text-align: center;"></th>
          </tr>
          <tr>
            <th class="sortable" scope="col" style="text-align: center;">
              <div class="text">복숭아</div>
            </th>
            <td><input type="text" id="id_cash" name="cash" /></td>
            <td><input type="submit" id="add0" name="add0" value="지급" onclick="Clicked(this)" /><input type="submit" name="remove0" value="회수" onclick="Clicked(this)" /></td>
          </tr>
          <tr>
            <th class="sortable" scope="col" style="text-align: center;">
              <div class="text">코인</div>
            </th>
            <td><input type="text" id=id_coin name="coin" /></td>
            <td><input type="submit" name="add1" value="지급" onclick="Clicked(this)" /><input type="submit" name="remove1" value="회수" onclick="Clicked(this)" /></td>
          </tr>
          <tr>
            <th class="sortable" scope="col" style="text-align: center;">
              <div class="text">당근</div>
            </th>
            <td><input type="text" id="id_bout" name="bout" /></td>
            <td><input type="submit" name="add2" value="지급" onclick="Clicked(this)" /><input type="submit" name="remove2" value="회수" onclick="Clicked(this)" /></td>
          </tr>
          <tr>
            <td colspan="3"><label style="width: 100px;"> <br /> <b>메모(지급사유) : </b>
            </label> <input type="text" id="memo" name="memo" size=60 /></td>
          </tr>
          <tr>
            <td colspan="3"><label style="width: 300px;"> <br /> <br /> <b>수신함 타이틀 :</b>
            </label> <input type="text" id="reward_title" name="reward_title" value="마시마로팍팍(관리자)" size=70 /></td>
          </tr>
        </thead>
      </table>
    </div>
  </form>
</body>
</html>